package com.example.anytest.gpsDemo.gps;

/**
 * Created by zhwp on 2018/5/9.
 */

public class SatAngleCalculateUtil {

    /**
     * 方法描述：获取卫星的仰角
     *
     * @param locationLongitude
     *            当前地理卫星经度
     * @param locationLatitude
     *            当前地理位置纬度
     * @param satLongitude
     *            卫星经度
     */
    public static double getSatElevation(double locationLongitude, double locationLatitude, double satLongitude){
        double angle2 = locationLongitude * 3.141592653589793D / 180.0D;
        double angle3 =locationLatitude * 3.141592653589793D / 180.0D;
        double angle4 = satLongitude * 3.141592653589793D / 180.0D;
        double angle5 = angle2 - angle4;
        //double angle1 = Math.atan(Math.tan(angle5) / Math.sin(angle3)) * 180.0D / 3.141592653589793D;
        angle5 = Math.atan((Math.cos(angle3) * Math.cos(angle5) - 0.15127D) / Math.sqrt(1.0D - Math.cos(angle3) * Math.cos(angle3) * Math.cos(angle5) * Math.cos(angle5))) * 180.0D / 3.141592653589793D;
        //angle2 = Math.atan(-Math.sin(angle2 - angle4) / Math.tan(angle3)) * 180.0D / 3.141592653589793D;

        double angle = Math.round(10000.0D * angle5) / 10000.0D;

        String angleStr = String.format("%.3f", angle);
        return Double.parseDouble(angleStr);

    }

    /**
     * 方法描述：获取卫星的极化角
     *
     * @param locationLongitude
     *            当前地理卫星经度
     * @param locationLatitude
     *            当前地理位置纬度
     * @param satLongitude
     *            卫星经度
     */
    public static double getSatPolarizingAngle(double locationLongitude, double locationLatitude, double satLongitude){
        double angle2 = locationLongitude * 3.141592653589793D / 180.0D;
        double angle3 = locationLatitude * 3.141592653589793D / 180.0D;
        double angle4 = satLongitude * 3.141592653589793D / 180.0D;
        //double angle5 = angle2 - angle4;
        //double angle1 = Math.atan(Math.tan(angle5) / Math.sin(angle3)) * 180.0D / 3.141592653589793D;
        //angle5 = Math.atan((Math.cos(angle3) * Math.cos(angle5) - 0.15127D) / Math.sqrt(1.0D - Math.cos(angle3) * Math.cos(angle3) * Math.cos(angle5) * Math.cos(angle5))) * 180.0D / 3.141592653589793D;
        angle2 = Math.atan(-Math.sin(angle2 - angle4) / Math.tan(angle3)) * 180.0D / 3.141592653589793D;

        double angle = Math.round(10000.0D * angle2) / 10000.0D;

        String angleStr = String.format("%.3f", angle);
        return Double.parseDouble(angleStr);

    }


    /**
     * 方法描述：获取卫星的方位角
     *
     * @param locationLongitude
     *            当前地理卫星经度
     * @param locationLatitude
     *            当前地理位置纬度
     * @param satLongitude
     *            卫星经度
     */
    public static double getSatAzimuth(double locationLongitude, double locationLatitude, double satLongitude){
        double angle2 = locationLongitude * 3.141592653589793D / 180.0D;
        double angle3 = locationLatitude * 3.141592653589793D / 180.0D;
        double angle4 = satLongitude * 3.141592653589793D / 180.0D;
        double angle5 = angle2 - angle4;
        double angle1 = Math.atan(Math.tan(angle5) / Math.sin(angle3)) * 180.0D / 3.141592653589793D;
        //angle5 = Math.atan((Math.cos(angle3) * Math.cos(angle5) - 0.15127D) / Math.sqrt(1.0D - Math.cos(angle3) * Math.cos(angle3) * Math.cos(angle5) * Math.cos(angle5))) * 180.0D / 3.141592653589793D;
       // angle2 = Math.atan(-Math.sin(angle2 - angle4) / Math.tan(angle3)) * 180.0D / 3.141592653589793D;
        double angle = Math.round(10000.0D * angle1) / 10000.0D;

        String angleStr = String.format("%.3f", angle);
        return Double.parseDouble(angleStr);


    }


}
